package com.tvunetworks.center.user.schedule;

import com.tvunetworks.center.user.service.GridEventService;
//import com.tvunetworks.leader.election.starter.LeaderElection;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @program: tvucc-aggregator
 * @description: GridEventTask
 * @author lebronchen
 * @create: 2020-01-03 15:38
 **/
@Component
@Slf4j
public class GridEventTask {

    @Autowired
    private GridEventService gridEventService;
//    @Autowired
//    private LeaderElection leaderElection;

    /**
     *  prePairTask
     */
    @Scheduled(initialDelayString = "10000", fixedDelayString = "${task.gridEvent.pre}")
    public void prePairTask(){
//        if (!leaderElection.isMaster()) {
//            log.info("GridEventTask prePairTask leader election not master");
//            return;
//        }
        gridEventService.prePairTask();
    }

    /**
     * eventStartTask
     */
    @Scheduled(initialDelayString = "14000", fixedDelayString = "${task.gridEvent.start}")
    public void eventStartTask(){
//        if (!leaderElection.isMaster()) {
//            log.info("GridEventTask eventStartTask leader election not master");
//            return;
//        }
        gridEventService.eventStartTask();
    }

    /**
     * eventEndTask
     */
    @Scheduled(initialDelayString = "18000", fixedDelayString = "${task.gridEvent.end}")
    public void eventEndTask(){
//        if (!leaderElection.isMaster()) {
//            log.info("GridEventTask eventEndTask leader election not master");
//            return;
//        }
        gridEventService.eventEndTask();
    }
}
